<template>
  <view class="select-container">
    <view class="title-section">
      <text class="main-title">开启音乐发现之旅</text>
      <text class="sub-title">上传照片，解锁专属音乐世界</text>
    </view>
    
    <view class="upload-area" @click="handleUpload">
      <view class="camera-icon"></view>
      <text class="upload-text">点击上传照片</text>
    </view>
  </view>
</template>

<script setup>
const handleUpload = () => {
  console.log('触发照片选择功能')
  // 这里可以添加实际的图片选择逻辑
 uni.chooseImage({
  count: 1,
  sizeType: ['original', 'compressed'],
  sourceType: ['album', 'camera'],
  success: (res) => {
    console.log(res.tempFilePaths[0])
    // 显示loading
    uni.showLoading({
      title: "图片正在上传AI分析",
      mask: true,

    })
    // 上传图片到后端http://192.168.110.41:9002/
    uni.uploadFile({
      url: 'http://192.168.110.41:9002/api/UserStatusAnalysis/',
      filePath: res.tempFilePaths[0],
      name: 'file',
      formData: {
        type: 'image'
      },
      success: (res) => {
        uni.hideLoading()
        console.log(res)
        /***
         * 跳转页面
         * 
         * {
    "data": "{\"code\": 200, \"data\": {\"emotion_analysis\": {\"emotion_type\": \"\\u5e73\\u9759\", \"confidence\": 0.7, \"facial_features\": {\"eyes\": \"\\u7741\\u773c\\uff0c\\u773c\\u795e\\u8f83\\u4e3a\\u5e73\\u548c\", \"eyebrows\": \"\\u81ea\\u7136\\u5f62\\u6001\\uff0c\\u65e0\\u660e\\u663e\\u4e0a\\u626c\\u6216\\u4e0b\\u5782\", \"mouth\": \"\\u5fae\\u95ed\\uff0c\\u5634\\u89d2\\u5e73\\u76f4\"}}, \"additional_notes\": \"\\u9762\\u90e8\\u6574\\u4f53\\u8868\\u60c5\\u8f83\\u4e3a\\u653e\\u677e\\uff0c\\u65e0\\u660e\\u663e\\u60c5\\u7eea\\u6ce2\\u52a8\\u8ff9\\u8c61\", \"possible_activities\": \"\\u7528\\u6237\\u53ef\\u80fd\\u5728\\u4f11\\u606f\\uff0c\\u6216\\u8005\\u5904\\u4e8e\\u4e00\\u4e2a\\u76f8\\u5bf9\\u5b89\\u9759\\u3001\\u4e0d\\u9700\\u8981\\u8fc7\\u591a\\u60c5\\u7eea\\u8868\\u8fbe\\u7684\\u5de5\\u4f5c\\u573a\\u666f\\u4e2d\\uff0c\\u6bd4\\u5982\\u5728\\u5e97\\u94fa\\u5185\\u8fdb\\u884c\\u4e00\\u4e9b\\u6574\\u7406\\u7b49\\u5e38\\u89c4\\u5de5\\u4f5c\", \"chat_id\": \"4e417e88-b00f-4d13-9a8e-84d947d66c6f\"}}",
    "statusCode": 200,
    "errMsg": "uploadFile:ok"
}
         * 
         * 
         */
         // 解析数据
         const data = JSON.parse(res.data)
         if(data.code == 200){
          console.log(data.data)
          // 保存信息到本地
          uni.setStorageSync("my_info", data.data)
      uni.showToast({
        title: "分析完成，正在跳转音乐推荐",
        mask: true,
        duration: 1500
      })
         }

         setTimeout(() => {
					console.log("setTimeout");
					uni.navigateTo({
						url:"/pages/analysis/index"
					})
				}, 1600);
          
      },
      fail: (err) => {
        console.log(err)
      }
    })
  }
 })
}
</script>

<style lang="scss" scoped>
.select-container {
  min-height: 100vh;
  background: linear-gradient(to bottom, #330066, #9966CC);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40rpx;
}

.title-section {
  margin-top: 100rpx;
  text-align: center;
  margin-bottom: 60rpx;
}

.main-title {
  font-size: 3rem;
  font-weight: bold;
  color: #FFFFFF;
  display: block;
  margin-bottom: 20rpx;
}

.sub-title {
  font-size: 1.5rem;
  color: #CC99FF;
  display: block;
}

.upload-area {
  width: 70%;
  aspect-ratio: 1;
  border: 3px dashed #FFFFFF;
  border-radius: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 40rpx;
}

.camera-icon {
  width: 80px;
  height: 80px;
  background-color: #CC99FF;
  border-radius: 50%;
  margin-bottom: 20rpx;
}

.upload-text {
  font-size: 1.2rem;
  color: #FFFFFF;
}
</style> 